package com.agileboot.domain.bot.conversationRecord.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.bot.conversationRecord.db.ConversationRecordEntity;
import com.agileboot.domain.bot.conversationRecord.db.ConversationRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ConversationRecordModelFactory {

    private final ConversationRecordService conversationRecordService;

    public ConversationRecordModel loadById(Long id) {
        ConversationRecordEntity entity = conversationRecordService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "会话记录");
        }
        return new ConversationRecordModel(entity, conversationRecordService);
    }

    public ConversationRecordModel create() {
        return new ConversationRecordModel(conversationRecordService);
    }
}
